package com.ghcnb.jyt.cmn.controller;

import com.ghcnb.jyt.cmn.service.DictService;
import com.ghcnb.jyt.common.result.Result;
import com.ghcnb.jyt.hosp.service.HospitalSetService;
import com.ghcnb.jyt.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "数据字典管理接口")
@RequestMapping("/admin/cmn/dict")
@RestController
//允许跨域访问
@CrossOrigin
public class DictController {

    @Autowired
    private DictService dictService;

    //数据字典导入接口
        @ApiOperation("数据字典导入")
        @PostMapping("importDict")
        public Result importDict(MultipartFile file){
            dictService.importDictData(file);
            return Result.ok();
        }




    //导出数据字典接口
    @ApiOperation(value = "数据字典导出")
    @GetMapping("exportData")
    public void exportDict(HttpServletResponse response){

            dictService.exportDictData(response);
    }



    @ApiOperation(value = "根据上级id获取子节点数据列表")
    @GetMapping("findChildData/{id}")
    //别脑残改PathVariable 变量名，和GetMapping要完全一致
    public Result<List<Dict>> findByParentId(@PathVariable Long id){
        List<Dict> list=dictService.findByParentId(id);
        return Result.ok(list);
    }

}
